import React, { useEffect } from 'react'
import { Location, connect, Dispatch } from 'umi'
import BottomNav from '@/components/BottomNav'
import style from './BasicLayout.less'
import '@/static/iconfont/iconfont.css'

import { ConnectState, UserModelState } from '../models/types'
interface BasicLayoutProps {
    location: Location;
    user: UserModelState;
    dispatch: Dispatch

}
const BasicLayout: React.FC<BasicLayoutProps> = props => {
    const { children, location, user, dispatch } = props
    useEffect(() => {
        if (dispatch) {
            dispatch({ type: 'user/fetchCurrent' })
        }
    }, [])
    const { pathname } = location
    const hiden = pathname !== '/login'
    return (
        <div className={style.main}>
            <article>{children}</article>
            <footer>
                {hiden && <BottomNav pathname={pathname}></BottomNav>}
            </footer>
        </div>
    )
}
export default connect(({ user }: ConnectState) => ({ user }))(BasicLayout)

